package com.cat.model.common.util;

import java.util.ArrayList;
import java.util.List;

public class PageUtil {
	
	/**
	 * @return [0]起始索引  [1]终止索引
	 * */
	public static int[] getStartAndEnd(int page, int pageSize, int totalCount){
		int start = (page - 1) * pageSize;
		int end = page * pageSize;
		
		if(start >= totalCount){
			start = totalCount;
		}
		if(end > totalCount){
			end = totalCount;
		}
		
		return new int[]{start, end};
	}
	
	public static void main(String[] args){
		List<String> list = new ArrayList<String>();
		list.add("1");
		list.add("2");
		list.add("3");
		list.add("4");
		list.add("5");
		list.add("6");
		int[] result = PageUtil.getStartAndEnd(3, 3, list.size());
		System.out.println(list.subList(result[0], result[1]));;
		System.out.println(result[0] + "," + result[1]);
	}
}
